﻿using System.Collections;
using System.Collections.Generic;

using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;

#endif

 

public class LchButtonAttribute : LabelAttribute
{
    
    public LchButtonAttribute(string label, string conditionalSourceField) : base(label, conditionalSourceField)
    {
    }

    public LchButtonAttribute(string label, string conditionalSourceField,int val) : base(label, conditionalSourceField,   val)
    {
    }
    public LchButtonAttribute(string label) : base(label)
    {
    }
}

#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(LchButtonAttribute))]
public class ButtonAttributeDrawer : ConditionalHidePropertyDrawer
{

    public override float BaseGetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        return EditorGUIUtility.singleLineHeight+5;
    }
    public override void DrawPropertyItem(LabelAttribute condHAtt, Rect position, SerializedProperty property, GUIContent label)
    {
        Rect _rect = position;
        _rect.height = EditorGUIUtility.singleLineHeight ;
 
        if (GUI.Button(_rect, label))
        {
            property.boolValue = true;
            Debug.Log("Clicked");
        }
    }
    

}

#endif



public class LchArrayOperaButtonAttribute : LabelAttribute
{
    public string[] items;
    public float[] width;
    public LchArrayOperaButtonAttribute(string[] items, float[] width, string conditionalSourceField) : base("", conditionalSourceField)
    {
        this.items = items;
        this.width = width;
    }

    public LchArrayOperaButtonAttribute(string[] items, float[] width, string conditionalSourceField, int val) : base("", conditionalSourceField, val)
    {
        this.items = items;
        this.width = width;
    }
    public LchArrayOperaButtonAttribute(string[] items, float[] width) : base("")
    {
        this.items = items;
        this.width = width;
    }
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(LchArrayOperaButtonAttribute))]
public class ArrayButtonAttributeDrawer : ConditionalHidePropertyDrawer
{

    public override float BaseGetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        return EditorGUIUtility.singleLineHeight + 5;
    }
    public override void DrawPropertyItem(LabelAttribute condHAtt, Rect position, SerializedProperty property, GUIContent label)
    {
        LchArrayOperaButtonAttribute buttons = (LchArrayOperaButtonAttribute)condHAtt;
        Rect _rect = position;
        _rect.height = EditorGUIUtility.singleLineHeight;


        for (int i = 0; i < buttons.items.Length; i++)
        {
            _rect.width = buttons.width[i];
            if (GUI.Button(_rect, buttons.items[i]))
            {
                property.floatValue = i + 1;

            }
            _rect.x += _rect.width + 3;
        }

    }
}
#endif
